layui.use(['table', 'admin', 'ax'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;

    /**
     * 入库单明细表管理
     */
    var StoragePutSingle = {
        tableId: "storagePutSingleTable"
    };

    /**
     * 初始化表格的列
     */
    StoragePutSingle.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'id', hide: true, title: '主键id'},
            {field: 'singleState', sort: true, title: '入库状态',templet: '#singleStateTpl'},
            {field: 'storageNumber', sort: true, title: '入库单号', style:'font-weight: 600;',width:180},
            {field: 'recommend', sort: true, title: '入库批次'},
            {field: 'positionNumber', merge: true, sort: true, title: '库位', style:'background-color: #ecf5ff;font-weight: 600;'},
            {field: 'trayNumber', sort: true, title: '托盘', style:'background-color: #ecf5ff;font-weight: 600;'},
            {field: 'goodsname', sort: true, title: '名称', style:'background-color: #dbf1e1;font-weight: 600;',width:270},
            {field: 'goodsNumber', sort: true, title: '编号', style:'background-color: #dbf1e1;font-weight: 600;'},
            {field: 'goodsNo', sort: true, title: '货号', style:'background-color: #dbf1e1;font-weight: 600;', totalRowText: '合计：'},
            {field: 'putNum', merge: true, sort: true, title: '应入数', totalRow: true, style:'background-color: #dbf1e1;font-weight: 600;'},
            {field: 'realNum', merge: true, sort: true, title: '实入数', totalRow: true, style:'background-color: #dbf1e1;font-weight: 600;'},
            {field: 'singleDateofmanufacture', sort: true, title: '生产日期', style:'background-color: #dbf1e1;font-weight: 600;'},
            {field: 'putWeight', title: '重量', totalRow: true},
            {field: 'detailedPutvolume', title: '体积', totalRow: true},
            {field: 'unitprice', title: '单价'},
            {field: 'singleMoney', title: '金额', totalRow: true},
            {field: 'singleLargeclass', title: '大类'},
            {field: 'singleGoodstype', title: '类别', hide: true},
            {field: 'goodsUnit', title: '单位'},
            {field: 'singlePacking', title: '包装'},
            {field: 'goodsSpecs', title: '规格'},
        ]];
    };

    /**
     * 点击查询按钮
     */
    StoragePutSingle.search = function () {
        var queryData = {};
        queryData['condition'] = $("#condition").val();
        table.reload(StoragePutSingle.tableId, {
            where: queryData, page: {curr: 1},
             done:function () {
            }
        });
    };

    /**
     * 导出excel按钮
     */
    StoragePutSingle.exportExcel = function () {
        var checkRows = table.checkStatus(StoragePutSingle.tableId);
        if (checkRows.data.length === 0) {
            Feng.error("请选择要导出的数据");
        } else {
            table.exportFile(tableResult.config.id, checkRows.data, 'xls');
        }
    };

    // 渲染表格
    var tableResult = table.render({
        elem: '#' + StoragePutSingle.tableId,
        url: Feng.ctxPath + '/storageStockDetailed/putlist?storageNumber='+Feng.getUrlParam("storageNumber"),
        page: true,
        limit: 40,
        height: "full-60",
        toolbar: '#toolbarfrom',
        cellMinWidth: 100,
        totalRow: true ,//开启合计行
        cols: StoragePutSingle.initColumn()
    });

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        StoragePutSingle.search();
    });

    // 导出excel
    $('#btnExp').click(function () {
        StoragePutSingle.exportExcel();
    });

    // 单击行事件
    table.on('row(' + StoragePutSingle.tableId + ')', function (obj) {
        var data = obj.data;
		$('div[lay-id="' + StoragePutSingle.tableId + '"]').find(".layui-table-body tr ").attr({ "style": "background:#FFFFFF" });//其他tr恢复原样
		$('div[lay-id="' + StoragePutSingle.tableId + '"]').find(obj.tr.selector).attr({ "style": "background:#e6e6e6;" });//改变当前tr颜色
    });

});
